import os
import zipfile

def compress_file_to_zip(source_file_path, destination_zip_path):
    
    if not os.path.isfile(source_file_path):
        raise FileNotFoundError(f"Source file does not exist: {source_file_path}")

    destination_dir = os.path.dirname(destination_zip_path)
    if not os.path.exists(destination_dir):
        os.makedirs(destination_dir)

    with zipfile.ZipFile(destination_zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
        zipf.write(source_file_path, arcname=os.path.basename(source_file_path))

    print(f"File '{source_file_path}' has been compressed to '{destination_zip_path}'.")

if __name__ == "__main__":
    # 获取 APPDATA 环境变量，如果不存在则使用默认值
    appdata_path = os.environ.get('APPDATA', '')
    if not appdata_path:
        raise EnvironmentError("APPDATA environment variable not found.")

    source_path = appdata_path + r"\io.github.clash-verge-rev.clash-verge-rev\profiles\Script.js"
    destination_path = "./Script.zip"

    try:
        compress_file_to_zip(source_path, destination_path)
    except Exception as e:
        print(f"An error occurred: {e}")
